//
//  AppDelegate.swift
//  ZSWeibo
//
//  Created by zsj1992 on 16/4/6.
//  Copyright © 2016年 ichange. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        
//        window?.rootViewController = defaultViewController()

        //window?.rootViewController = ZSWelcomeViewController()
        
        window?.rootViewController = ZSTabBarController()
       
//        window?.rootViewController = ZSPictureSelectorController()
        window?.makeKeyAndVisible()

        //appdelegate监听这个通知,这个通知一旦被post,appdelegate就调用对应的selector,
    
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeRootViewController:", name: "changeRootViewController", object: nil)

        return true
    }
    
    
    deinit{
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
}


extension AppDelegate {

    func defaultViewController()->(UIViewController){

        return ZSUserAccountViewModel.sharedUserViewModel.userLogin ? ZSWelcomeViewController() : ZSTabBarController()
        
    }

    
    
    func changeRootViewController (n:NSNotification){
        
        if n.object != nil{
        window?.rootViewController = ZSTabBarController()
        }else{
        window?.rootViewController = ZSWelcomeViewController()
        }

    }
}


